package com.dyh.quickdemo.dasync;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.function.Consumer;

/*
@Author=Joey Wheeler
@Date=2021/3/11 16:58
*/
@Service
public class ThatBiz {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    AsyncHandlerFacadeService asyncHandlerFacadeService;



    public void x(long id){
        $sx(id);
        logger.info("{} send",Thread.currentThread().getName() );
        asyncHandlerFacadeService.send(new AsyncEventContext("That.x",id));
    }


    private void $sx(long id){
        logger.info("ThatBiz.x {}",id);
    }

    @PostConstruct
    public void pc(){
        asyncHandlerFacadeService.regist("That.x",(Consumer<Long>) this::$sx);
    }
}
